home *** CD-ROM | disk | FTP | other *** search
- --------------------------------------------------------------------------------
- -- Weapon Plasma Gun + Projectile Ray
- -- Original Carnage Contest Weapon
- -- Script by DC, August 2009, www.UnrealSoftware.de
- --------------------------------------------------------------------------------
-
- -- Setup Tables
- if cc==nil then cc={} end
- cc.plasmagun={}
- cc.plasmagun.ray={}
-
- -- Load & Prepare Ressources
- cc.plasmagun.gfx_wpn=loadgfx("weapons/plasmagun.bmp") -- Weapon Image
- setmidhandle(cc.plasmagun.gfx_wpn)
- cc.plasmagun.gfx_pro=loadgfx("weapons/lasershot.png") -- Projectile Image
- setmidhandle(cc.plasmagun.gfx_pro)
- cc.plasmagun.sfx_attack=loadsfx("laser.wav") -- Attack Sound
- cc.plasmagun.sfx_impact=loadsfx("laserimpact.wav") -- Impact Sound
-
- --------------------------------------------------------------------------------
- -- Weapon: Plasma Gun
- --------------------------------------------------------------------------------
-
- cc.plasmagun.id=addweapon("cc.plasmagun","Plasma Gun",cc.plasmagun.gfx_wpn,3) -- Add Weapon (3 uses)
- cc.plasmagun.ammo=3 -- 3 Shots
-
- function cc.plasmagun.draw() -- Draw
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- drawinhand(cc.plasmagun.gfx_wpn,6,0)
- -- HUD ammobar
- if cc.plasmagun.ammo-weapon_shots>0 then
- hudammobar(cc.plasmagun.ammo-weapon_shots,cc.plasmagun.ammo)
- end
- -- HUD Crosshair
- if cc.plasmagun.ammo-weapon_shots>0 then
- hudcrosshair(7,3)
- end
- end
-
- function cc.plasmagun.attack(attack) -- Attack
- -- Decrement timer
- if weapon_timer>0 then
- weapon_timer=weapon_timer-1
- end
- -- Attack
- if weapon_shots<cc.plasmagun.ammo and weapon_timer<=0 and attack==1 then
- -- No more weapon switching!
- useweapon(0)
- -- Reset Timer
- weapon_timer=15
- -- Attack
- playsound(cc.plasmagun.sfx_attack)
- weapon_shots=weapon_shots+1
- id=createprojectile(cc.plasmagun.ray.id)
- projectiles[id]={}
- -- Ignore collision with current player at beginning
- projectiles[id].ignore=playercurrent()
- -- Set initial position of projectile
- projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
- projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
- -- Set speed of projectile
- projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*6.0
- projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*6.0
- -- Timer
- projectiles[id].timer=0
- -- Initial movement
- projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
- projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
- for i=1,3,1 do
- if cc.plasmagun.ray.move(id)==1 then
- break
- end
- end
- -- Effects
- recoil(3)
- particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
- particlecolor(0,255,0)
- particlefadealpha(0.01)
- particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
- particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
- particlefadealpha(0.005)
- -- End Turn
- if (weapon_shots>=cc.plasmagun.ammo) then
- endturn()
- end
- end
- end
-
- --------------------------------------------------------------------------------
- -- Projectile: Ray
- --------------------------------------------------------------------------------
-
- cc.plasmagun.ray.id=addprojectile("cc.plasmagun.ray") -- Add Projectile
-
- function cc.plasmagun.ray.draw(id) -- Draw
- -- Setup draw mode
- setblend(blend_light)
- setalpha(1)
- setcolor(0,255,0)
- setscale(1.0,0.5)
- -- Calculate projectile rotation
- setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
- -- Draw projectile
- drawimage(cc.plasmagun.gfx_pro,projectiles[id].x,projectiles[id].y)
- -- Draw Arrow if out of Screen
- outofscreenarrow(projectiles[id].x,projectiles[id].y)
- end
-
- function cc.plasmagun.ray.update(id) -- Update
- -- Particle Tail
- particle(p_lightpuff,projectiles[id].x,projectiles[id].y)
- particlespeed(math.random(-5,5)*0.1,math.random(-5,5)*0.1)
- particlefadealpha(0.05)
- particlesize(math.random(20,40)*0.1,math.random(20,40)*0.1)
- particlecolor(0,255,0)
- -- Move
- cc.plasmagun.ray.move(id)
- end
-
- function cc.plasmagun.ray.move(id)
- -- Timer (free after 10 secs)
- projectiles[id].timer=projectiles[id].timer+1
- if projectiles[id].timer>500 then
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
- -- Move (in substep loop for optimal collision precision)
- msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
- msubx=projectiles[id].sx/msubt
- msuby=projectiles[id].sy/msubt
- for i=1,msubt,1 do
- projectiles[id].x=projectiles[id].x+msubx
- projectiles[id].y=projectiles[id].y+msuby
- -- Collision
- if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)==1 then
- if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
- -- Cause damage
- arealdamage(projectiles[id].x,projectiles[id].y,25,25)
- -- Destroy terrain
- terrainexplosion(projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,22,2)
- -- Crater
- if math.random(1,2)==1 then
- terrainalphaimage(gfx_crater100,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,math.random(6,9)*0.1,0,25,0)
- else
- terrainalphaimage(gfx_crater125,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,math.random(6,9)*0.1,0,25,0)
- end
- -- Effects
- playsound(cc.plasmagun.sfx_impact)
- particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
- particlefadealpha(0.006)
- particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
- particlesize(1.5,1.5)
- particlecolor(0,255,0)
- particlefadealpha(0.01)
- for j=1,20,1 do
- particle(p_lightpuff,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
- particlespeed(math.random(-20,20)*0.1,math.random(-20,20)*0.1)
- particlefadealpha(0.04)
- particlesize(math.random(40,70)*0.1,math.random(40,70)*0.1)
- particlecolor(0,255,0)
- end
- for i=1,3 do
- particle(p_spark,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
- particlecolor(0,255,0)
- particlefadealpha(0.01)
- particlesize(1.5,1.5)
- end
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- else
- projectiles[id].ignore=0
- end
- -- Water
- if (projectiles[id].y)>getwatery()+5 then
- -- Effects
- playsound(cc.plasmagun.sfx_impact)
- particle(p_smoke,projectiles[id].x,projectiles[id].y)
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- end
- end